package com.xyebank.ledger.service.xjfq.adaper;

import java.text.ParseException;
import java.util.Date;

import com.xyebank.ledger.util.DateConverter;
import org.modelmapper.AbstractConverter;
import org.modelmapper.Converter;
import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LPaymentInf;
import com.xyebank.ledger.service.common.conveter.PayBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.DateUtil;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.vo.deal.XJFQCashCreditVo;

@Component(value = "XJFQCreditBeanConverter")
public class XJFQCreditBeanConverter implements PayBeanConverter<XJFQCashCreditVo> {

	ModelMapper modelMapper = new ModelMapper();

	// 不能采取注入方式
	private DateConverter dateConverter = new DateConverter();

	class NXApplyPropertyMap extends PropertyMap<XJFQCashCreditVo, LPaymentInf> {
		// 注意 不要有重复的映射，不然会报错
		protected void configure() {
			// 享宇订单号
			map(source.getOrderNo(), destination.getXyOrderNo());
			// 提现订单号
			map(source.getContactNo(), destination.getOrgOrderNo());
			// 申请人电话
			map(source.getMobile(), destination.getMblNo());
			// 申请提现时间
			using(dateConverter).map(source.getApplTime(), destination.getApplyTime());
			// 提现审批状态
			map(source.getApprovalStatus(), destination.getApprovalStatus());
			// 提现审批时间
			using(dateConverter).map(source.getApprovaTime(), destination.getApprovalTime());
			// 放款金额
			map(source.getApprovalAmount(), destination.getLoanAmount());
			// 放款时间
			map(source.getApprovaTime(), destination.getLoanTime());
			// 放款期数
			map(source.getApprovalPeriod(), destination.getLoanPeriod());
		}
	}

	public XJFQCreditBeanConverter() {
		modelMapper.addMappings(new NXApplyPropertyMap());
	}

	@Override
	public LPaymentInf covert(XJFQCashCreditVo x) {
		LPaymentInf entity = modelMapper.map(x, LPaymentInf.class);
		entity.setDataSource(x.getChannelNo().equals("80008833") ? CommonConstant.JRY_STR : CommonConstant.SJD_STR);
		entity.setProductNo(ProductConstant.XJFQ_PROD_ID);
		entity.setOrgNo(ProductConstant.XJFQ_LOAN_ORG);
		entity.setId(IDUtil.generateId(x.getId().toString(), "xjfq_credit"));
		return entity;
	}
}
